package com.lottery.ruok.lottrey.ui.widget;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v4.view.animation.LinearOutSlowInInterpolator;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.activity.ActivitiesDialogActivity;
import com.lottery.ruok.lottrey.ext.GlideExt;
import com.lottery.ruok.lottrey.retrofitModule.response.ActivityListResponse;
import com.lottery.ruok.lottrey.ui.component.BaseRelativeLayout;
import com.lottery.ruok.lottrey.utils.ConstantUtil;
import com.lottery.ruok.lottrey.utils.DisplayUtil;

import butterknife.BindView;
import butterknife.OnClick;

public class ActivitiesSingleMissions extends BaseRelativeLayout {


    @BindView(R.id.missions_image)
    ImageView missionsImage;
    @BindView(R.id.missions_title)
    TextView missionsTitle;
    @BindView(R.id.missions_progress)
    AlterableProgressBar missionsProgress;
    @BindView(R.id.wave_view)
    WaveView waveView;
    @BindView(R.id.tv_status)
    TextView tvStatus;
    @BindView(R.id.fl)
    FrameLayout fl;
    private String mActivitiesId;

    private ActivityListResponse.ListBean.MissionsBean mData;

    public ActivitiesSingleMissions(Context context) {
        super(context);
    }

    @Override
    protected void init(Context context, AttributeSet attrs, int defStyleAttr) {

    }

    @Override
    protected void initView(Context context) {
        setContentView(R.layout.activities_single_missions);
        //设置背景动画
        waveView.setDuration(2000);
        waveView.setMaxRadius(DisplayUtil.dip2px(80 / 2, mContext));
        waveView.setStyle(Paint.Style.FILL);
        //设置背景动画的颜色
        waveView.setColor(Color.RED);
        waveView.setInterpolator(new LinearOutSlowInInterpolator());
        waveView.start();
    }

    @Override
    protected void load(Context context) {

    }

    public void setData(ActivityListResponse.ListBean.MissionsBean mData, String activitiesId,int activitiesStatus) {
        this.mActivitiesId = activitiesId;
        this.mData = mData;
        GlideExt.setBackgroundDrawable(mContext, mData.getIcon().getImage(), missionsImage, R.mipmap.activitybet);
        missionsProgress.setProgressBarStyle(mData);
        missionsTitle.setText(mData.getTitle().getValue());
        missionsTitle.setTextColor(Color.parseColor(mData.getTitle().getColor()));
        missionsProgress.setProgress(mData.getProgressbar().getValue());
        switch (mData.getStatus()) {
            case ConstantUtil.NO_STARTED:
                waveView.stop();
                waveView.setVisibility(GONE);
                break;
            case ConstantUtil.PROCESSING:
                waveView.setVisibility(VISIBLE);
                waveView.start();
                break;
            case ConstantUtil.PENDIENT_REVIEW:
                waveView.stop();
                waveView.setVisibility(GONE);
                break;
            case ConstantUtil.READY_TO_RECEIVE_THE_REWARDS:
                waveView.setVisibility(GONE);
                waveView.stop();
                tvStatus.setVisibility(VISIBLE);
                tvStatus.setBackgroundResource(R.drawable.bg_corners_100_14);
                tvStatus.getBackground().mutate().setAlpha(200);
                tvStatus.setText("未领");
                break;
            case ConstantUtil.COMPLETED:
                waveView.setVisibility(GONE);
                tvStatus.setVisibility(VISIBLE);
                waveView.stop();
                tvStatus.setBackgroundResource(R.drawable.bg_corners_100_13);
                tvStatus.getBackground().mutate().setAlpha(200);
                tvStatus.setText("已领");
                break;
        }
        if (activitiesStatus == 3 || activitiesStatus == 4) {
            waveView.stop();
            waveView.setVisibility(GONE);
        }
    }

    @OnClick(R.id.fl)
    public void onViewClicked() {
        Intent intent = new Intent(mContext, ActivitiesDialogActivity.class);
        intent.putExtra("data", mData);
        intent.putExtra("activities_id", mActivitiesId);
        mContext.startActivity(intent);
    }

    public void setHideMissionsTitle() {
        missionsTitle.setVisibility(GONE);
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) missionsProgress.getLayoutParams();
//        lp.topMargin = (int) DisplayUtil.dip2px(39, mContext);
        lp.leftMargin = (int) DisplayUtil.dip2px(7,mContext);
        missionsProgress.setLayoutParams(lp);
    }

}
